package com.bgrconsulting.stockorderentry.service.rest.impl;

import java.util.Map;
import java.util.Set;

import javax.ws.rs.Path;
import javax.ws.rs.GET;
import javax.ws.rs.Produces;
import com.bgrconsulting.stockorderentry.service.converter.AccountListConverter;
import com.bgrconsulting.stockorderentry.service.dao.AccountResponseDao;
import com.bgrconsulting.stockorderentry.service.model.Account;
import com.bgrconsulting.stockorderentry.service.model.AccountList;

@Path("/accounts/rest/accountlist/")
public class AccountListResource {
 
 @GET
 @Produces({"application/xml", "application/json"})
 public AccountListConverter getAccounts() {
	 
	    //TODO: Change this to actually retrieve the accounts based on logged user.
	 
	    //Account acc0 = new Account("INDIVUAL", "83353546S", "MARGIN", "", 657.37, "INDIVIDUAL");
	    //Account acc1 = new Account("INDIVUAL", "83353547A", "MARGIN", "", 658.37, "INDIVIDUAL");
	    //Account acc2 = new Account("INDIVUAL", "83353548C", "MARGIN", "", 659.37, "INDIVIDUAL");
	    //Account acc3 = new Account("INDIVUAL", "83353549E", "MARGIN", "", 660.37, "INDIVIDUAL");
	    //Account acc4 = new Account("INDIVUAL", "83353550J", "MARGIN", "", 661.37, "INDIVIDUAL");
	    //Account acc5 = new Account("INDIVUAL", "83353551K", "MARGIN", "", 662.37, "INDIVIDUAL");
	    
	    Account[] acv = new Account[AccountResponseDao.instance.getModel().size()];
	    	    
	    Set accountIds = AccountResponseDao.instance.getModel().keySet();
	    int i = 0;
	    for(Object accountId : accountIds) {
	    	acv[i] =  AccountResponseDao.instance.getModel().get(accountId);
	    	i++;
	    }
	    
	    AccountList al = new AccountList(acv);
	    
	    AccountListConverter alc = new AccountListConverter(al);
	 
        return alc;
    }
}